livecodefandomcom-20200223-history
Functions
Function handlers are commonly called functions. LiveCode has many built-in Functions, a list of them is found at the end of this article. A programmer can create their own Function, called Custom Functions. This article is mainly about how to structure and use Custom Functions, A Custom Function is very similar to a Custom Message Handler. But there are differences, so don't confuse the two of them. However, which one you use usually comes down to personal preference. See also Message Handlers, sometimes called Commands. Structure The first line of a Custom Function must start with the word "function", followed my the name of the Function. That name is also the name of the message which causes its execution. If there are any function parameters, they are placed as a list after the name of the Function. The last line of a Function must start with the word "end", followed by the name of the Function. Between the first line of the Function and the last are the list of statements that make up the Function. The statement list must include at least one Return statement. When the Function is executed, a Return statement must be executed. The first Return statement that is executed stops the Function execution and returns the value, it is the effective end of the Function. A Function example: function myWeek theDays -- myWeek has one parameter: theDays return theDays + 7 -- 7 is added to theDays, then it is end myWeek -- returned to the calling statement. Calling Statement The Calling Statement starts with the name of the Function. If there are any function parameters, they are placed as a list after the name of the Function in the Calling Statement. The parameter list in the Calling statement must match the parameter list in the Function, both in the number of the parameters and the order. Each parameter in the parameter list of the Calling Statement must be an appropriate value or a variable containing the appropriate value. The parameter list in the Calling Statement must be enclosed in parenthesis. Use only one set of parenthesis. The Calling Statement can be placed in any handler, which is then called the Calling handler. When the Calling Statement is executed, the name and parameter list becomes the message which travels along the message path until it encounters the Function, which is then executed. The value that is returned by the Function is returned to the Calling Statement as if it was a variable. Therefore, the Calling Statement must be used like a variable in any of the LiveCode statements in the Calling handler. A Calling handler for the above example function: on mouseUp -- myWeek is called in this mouseUp handler. put myWeek (4) into thisWeek -- thisWeek = 11 answer "myWeek = " & thisWeek -- answer shows myWeek = 11 end mouseUp -- end mouseUp handler Another Function example: function Fred george, bob, dude -- george 1st number, bob the 2nd and dude the 3rd put george + bob - dude into Temp -- Temp = 1st + 2nd - 3rd return Temp -- Temp is returned to the calling statement end Fred -- end Fred function Another Calling handler: on mouseUp -- This is the calling handler mouseUp put Fred(4,5,6) into Susan -- Fred = 3 and Susan = 3 end mouseUp -- end mouseUp handler Private Functions A Private Function is placed in the same script as the Calling handler. When LiveCode executes a Calling Statement, it sends the message to the local script first. If a Private Function is encountered, then LiveCode executes that Private Function. The message doesn't travel far. The first line of a Private Function must start with the word "private", followed by the word "function", followed by the name of the Function. If there are any function parameters, they are placed as a list after the name of the Function. The parameter list of a Private Function operates the same as the parameter list of a Function. Common Built-in Functions Please help to complete this list * abs * acos * aliasReference * alternateLanguages * altKey *androidHasPermission *androidPermissionExists *androidRequestPermission * annuity * arrayDecode * arrayEncode * asin * atan * atan2 * average * averageDeviation * backScripts * base64Decode * base64Encode * baseConvert * binaryDecode * binaryEncode * buildNumber * byteOffset * byteToNum * cachedURLs * capsLockKey * ceil * charToNum * ciphernames * clickChar * clickCharChunk * clickChunk * clickField * clickH * clickLine * clickLoc * clickStack * clickText * clickV * clipboard * codepointOffset * codepointProperty * codepointToNum * codeunitOffset * colorNames * commandArguments * commandKey * commandName * commandNames * compound * compress * constantNames * controlAtLoc * controlAtScreenLoc * controlKey * copyResource * cos * date * dateFormat * decompress * deleteRegistry * deleteResource * DiffCompare *DiffCompareFiles *DiffPatch * diskSpace * DNSServers * dragDestination * dragSource * drawingSvgCompile * drawingSvgCompileFile * driverNames * dropChunk * environment * errorObject *EventCapsLockKey *EventCommandKey * EventShiftKey * exists * exp * exp1 * exp10 * exp2 * extents * files * floor * flushEvents * focusedObject * folders * fontLanguage * fontNames * fontSizes * fontStyles * format * foundChunk * foundField * foundLine * foundLoc * foundText * frontScripts * functionNames * geometricMean *Getopt * getResource * getResources * globalLoc * globalNames * harmonicMean * hasMemory * heapSpace * hostAddress * hostAddressToName * hostName * hostNameToAddress *iconNames * interrupt * intersect * iphoneApplicationIdentifier * iphoneDeviceResolution * iphoneDeviceScale * iphoneDoNotBackupFile * iphoneFileDataProtection * iphoneGetNotificationBadgeValue * iphoneHeadingCalibrationTimeout * iphoneIdentifierForVendor * iphoneRemoteControlEnabled * iphoneSystemIdentifier * isNumber * ISOToMac * itemOffset * JsonExport * JsonImport * keys * keysDown * length * libURLErrorData * libURLFormData * libURLftpCommand * libURLLastHTTPHeaders * libURLLastRHHeaders * libURLMultipartFormAddPart * libURLMultipartFormData * libURLVersion * licensed * lineOffset * listRegistry * ln * ln1 * loadedExtensions * localLoc * localNames * log10 * log2 * longFilePath * machine * macToISO * mainStacks * matchChunk * matchText * matrixMultiply * max * mcEncrypt * mCISendString * mcLicense * md5Digest * measureText * measureUnicodeText * median * menuButton * menus * merge * mergMarkdownToXHTML * messageAuthenticationCode * milliseconds * mimeEncodeAsMIMEMultipartDocument * mimeEncodeFieldAsMIMEMultipartDocument * mimeEncodeForMIMETransfer * mimeTheExtensionsOfMIMEType * mimeTheMIMETypeOfExtension * mimeTheMIMEVersion * min * mobileAdGetTopLeft * mobileAdGetVisible * mobileAds * mobileAllowedOrientations * mobileBuildInfo * mobileCameraFeatures * mobileCanComposeTextMessage * mobileCanMakePurchase * mobileCanSendMail * mobileCanTrackHeading * mobileCanTrackLocation * mobileControlGet * mobileControls * mobileControlTarget * mobileCurrentHeading * mobileCurrentLocale * mobileCurrentLocation * mobileDeviceOrientation * mobileGetContactData * mobileGetDeviceToken * mobileGetLaunchData * mobileGetLaunchURL * mobileGetNotificationDetails * mobileGetRegisteredNotifications * mobileIdleTimerLocked * mobileIsNFCAvailable * mobileIsNFCEnabled * mobileIsVoiceOverRunning * mobileLocationAuthorizationStatus * mobileNextSoundOnChannel * mobileOrientation * mobileOrientationLocked * mobilePixelDensity * mobilePreferredLanguages * mobilePurchaseError * mobilePurchaseGet * mobilePurchases * mobilePurchaseState * mobilesNFCAvailable *mobilesNFCEnabled * mobileSensorAvailable * mobileSensorReading * mobileSoundChannels * mobileSoundChannelStatus * mobileSoundChannelVolume * mobileSoundOnChannel * mobileStoreCanMakePurchase * mobileStoreProductProperty * mobileStorePurchasedProducts * mobileStorePurchaseError * monthNames * mouse * mouseChar * mouseCharChunk * mouseChunk * mouseClick * mouseColor * mouseControl * mouseH * mouseLine * mouseLoc * mouseStack * mouseText * mouseV * movie * movingControls * nativeCharToNum * normalizeText * number * numToByte * numToChar * numToCodepoint * numToNativeChar * offset * openFiles * openProcesses * openProcessIDs * openSockets * openStacks * optionKey * paragraphOffset * param * paramCount * params * peerAddress * pendingMessages * platform * populationStandardDeviation * populationVariance * processID * processor * propertyNames * qtEffects * qtVersion * queryRegistry * random * randomBytes * recordCompressionTypes * recordFormats * recordLoudness * remoteControlReceived * replaceText * result * revAppVersion * revBrowserAddJavaScriptHandler * revBrowserCallScript * revBrowserExecuteScript * revBrowserGet * revBrowserInstances * revBrowserOpen * revBrowserOpenCef * revBrowserRemoveJavaScriptHandler * revCurrentRecord * revCurrentRecordIsFirst * revCurrentRecordIsLast * revDatabaseColumnCount * revDatabaseColumnIsNull * revDatabaseColumnLengths * revDatabaseColumnNamed * revDatabaseColumnNames * revDatabaseColumnNumbered * revDatabaseColumnTypes * revDatabaseConnectResult * revDatabaseCursors * revDatabaseID * revDatabaseTableNames * revDatabaseType * revDataFromQuery * revdb_closecursor * revdb_commit * revdb_disconnect * revdb_execute * revdb_movefirst * revdb_movelast * revdb_movenext * revdb_moveprev * revdb_rollback * revGetDatabaseDriverPath * revGetSpeechVolume * revIsSpeaking * revLicenseType * revLoadedStacks * revMacFromUnixPath * revNumberOfRecords * revOpenDatabase * revOpenDatabases * revQueryDatabase * revQueryIsAtEnd * revQueryIsAtStart * revQueryResult * revSpeechVoices * revUnixFromMacPath * revXMLAttribute * revXMLAttributes * revXMLAttributeValues * revXMLChildContents * revXMLChildNames * revXMLCreateTree * revXMLCreateTreeFromFile * revXMLCreateTreeFromFileWithNamespaces * revXMLCreateTreeWithNamespaces * revXMLDataFromXPathQuery * revXMLEvaluateXPath * revXMLFirstChild * revXMLMatchingNode * revXMLNextSibling * revXMLNodeContents * revXMLNumberOfChildren * revXMLParent * revXMLPreviousSibling * revXMLRootNode * revXMLRPC_CreateRequest * revXMLRPC_Documents * revXMLRPC_Error * revXMLRPC_Execute * revXMLRPC_GetHost * revXMLRPC_GetParam * revXMLRPC_GetParamCount * revXMLRPC_GetParamNode * revXMLRPC_GetParamType * revXMLRPC_GetPath * revXMLRPC_GetPort * revXMLRPC_GetProtocol * revXMLRPC_GetRequest * revXMLRPC_GetResponse * revXMLRPC_GetSocket * revXMLText * revXMLTree * revXMLTrees * revXMLValidateDTD * revZipDescribeItem * revZipEnumerateItems * revZipOpenArchives *rreHardcopyIsAvailable * round * screenColors * screenDepth * screenLoc * screenName * screenRect * screenType * screenVendor * scriptLimits * seconds * selectedButton * selectedChunk * selectedField * selectedImage * selectedLine * selectedLoc * selectedObject * selectedText * sentenceOffset * setregistry * setResource * sha1Digest * shell * shiftKey * shortFilePath * sin * sound * specialFolderPath * sqrt * stacks * stackSpace * standardDeviation * statRound * sum * sysError * systemVersion * tan * target * tempName * textDecode * textEncode * textHeightSum * ticks * time * tokenOffset * toLower * tool * Topstack * toUpper * transpose * truewordOffset * trunc * uniDecode * uniEncode * URLDecode * URLEncode * URLResponse * URLStatus * uuid * value * variableNames * variance * vectorDotProduct * version * volumes * waitDepth * weekdayNames * within * wordOffset * xsltApplyStylesheet * xsltApplyStylesheetFromFile * xsltLoadStylesheet * xsltLoadStylesheetFromFile Category:Functions